﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Aplikacja_PostgreSQL
{
    public partial class Settings : Form
    {
        public Settings()
        {
            InitializeComponent();
            tbDatabase.Text = MainWindow.DbDatabase;
            tbSerwer.Text = MainWindow.DbSerwer;
            tbUserID.Text = MainWindow.DbUserID;
            tbPass.Text = MainWindow.DbPassword;
            tbPort.Text = MainWindow.DbPort;
        }
        public class AppSettingsEventArgs : EventArgs
        {
            private string database;

            public string Database
            {
                get { return database; }
                set { database = value; }
            }
            private string password;

            public string Password
            {
                get { return password; }
                set { password = value; }
            }
            private string userid;

            public string Userid
            {
                get { return userid; }
                set { userid = value; }
            }
            private string port;

            public string Port
            {
                get { return port; }
                set { port = value; }
            }
            private string serwer;

            public string Serwer
            {
                get { return serwer; }
                set { serwer = value; }
            }
            public AppSettingsEventArgs(string s, string d, string u, string pass, string port)
            {
                database = d;
                serwer = s;
                password = pass;
                this.port = port;
                userid = u;
            }
        }

        public delegate void AppSettingsEventHandler(object sender, AppSettingsEventArgs e);

        public event AppSettingsEventHandler Accept;

        public string userID
        {
            get { return tbUserID.Text; }
            set { tbUserID.Text = value; }
        }
        public string password
        {
            get { return tbPass.Text; }
            set { tbPass.Text = value; }
        }
        public string serwer
        {
            get { return tbSerwer.Text; }
            set { tbSerwer.Text = value; }
        }
        public string port
        {
            get { return tbPort.Text; }
            set { tbPort.Text = value; }
        }
        public string database
        {
            get { return tbDatabase.Text; }
            set { tbDatabase.Text = value; }
        }
        private void btAccept_Click(object sender, EventArgs e)
        {
            if (Accept != null)
                Accept(this, new AppSettingsEventArgs(serwer, database, userID, password, port));
            Hide();
        }

        private void btCancel_Click(object sender, EventArgs e)
        {
            Hide();
        }
        

            

    }
}
